package housekeeping.util;

import lombok.Data;

/**
 * @version 1.0
 * @Author Du
 * @Date 2025/7/7 02:04
 * @注释
 */
@Data
public class ServerResult<T> {
    private Integer code;
    private String message;
    private T data;

    public static <T> ServerResult<T> ok(T data){
        ServerResult<T> result = new ServerResult<>();
        result.setCode(200);
        result.setMessage("OK");
        result.setData(data);
        return result;
    }

    public static ServerResult<Void> ok(){
        return ok(null);
    }

    public static <T> ServerResult<T> error(T data){
        ServerResult<T> result = new ServerResult<>();
        result.setCode(404);
        result.setMessage("error");
        result.setData(data);
        return result;
    }

    public static ServerResult<Void> error(Integer code, String message){
        ServerResult<Void> result = new ServerResult<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static ServerResult<Void> error(String message) {
        return error(500, message); // 默认使用 500 状态码
    }

}
